package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;

import com.sky.dto.EmployeePageQueryDTO;
import com.sky.pojo.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployeeService;

import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Api(tags = "员工管理")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @ApiOperation("修改")
    @PutMapping
    public Result<String> update(@RequestBody Employee employee){
        log.info("修改员工：{}", employee);
        return employeeService.update(employee);
    }


    /*
    * 根据id查询
    * */
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result<Employee> findById(@PathVariable(name = "id") Long id){
        return employeeService.findById(id);
    }

    /*
    * 启用或禁用员工账号
    * */
    @ApiOperation("启用或禁用")
    @PostMapping("/status/{status}")
    public Result<String> startOrStop(@PathVariable (name= "status" ) Integer status, Long id){
        log.info("启用或禁用,status{},id{}",status, id);
        return employeeService.startOrStop(status, id);
    }

    /*
    * 员工管理分页查询
    * @param employeePageQueryDTO
    * */
    @ApiOperation("员工管理分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(EmployeePageQueryDTO employeePageQueryDTO){
        log.info("员工分页查询，参数：{}", employeePageQueryDTO);
        return employeeService.pageQuery(employeePageQueryDTO);

    }


    /*
    * 新增员工
    * @param employeeDTO
    * */
    @ApiOperation("新增员工")
    @PostMapping
    public Result<?> addEmployee(@RequestBody EmployeeDTO employeeDTO) {
        log.info("新增员工：{}", employeeDTO);
        return employeeService.addEmp(employeeDTO);
    }


    /**
     * 登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("员工登录")
    //@ApiImplicitParam(name = "employeeLoginDTO", value = "员工登录信息DTO", required = true, dataType = "EmployeeLoginDTO")
    public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
        log.info("员工登录：{}", employeeLoginDTO);
        return employeeService.login(employeeLoginDTO);

    }


    /**
     * 退出
     *
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation("员工退出")
    public Result<String> logout() {return Result.success();}





}
